package com.project.controller;

import com.project.bean.RoomBean;
import com.project.bean.UnitBean;
import com.project.service.IRoomService;
import com.project.service.IUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("room")
public class RoomController {

    @Autowired
    private IRoomService service;

    @Autowired
    private IUnitService unitService;

    @RequestMapping("findByItem")
    public List<RoomBean> findByItem(String address, String state,
                                     String bool, String type){

        return service.findByItem(address,state,bool,type);
    }

    @RequestMapping("del")
    public String del(int id){
        service.del(id);
        return "ok";
    }

    @RequestMapping("add")
    public String add(RoomBean room){
        service.add(room);
        return "ok";
    }

    @RequestMapping("findById")
    public RoomBean findById(int id){

        return service.findById(id);
    }

    @RequestMapping("findUnit")
    public List<UnitBean> findUnit(int roomId){

        return unitService.findAll(roomId);
    }

    @RequestMapping("addUnit")
    public String addUnit(UnitBean unit,int roomId){
        unitService.add(unit,roomId);
        return "ok";
    }

    @RequestMapping("updateState")
    public String updateState(int unitId,int roomId){

        unitService.update(unitId,roomId);
        return "ok";
    }
}
